package practise.alogrithm.hundredInterviewQuestions.secondTime;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Richard on 7/26/2014.
 */
public class LastNumberInCircle {
    public Integer find(List<Integer> array,int m){
        for(int index =m%array.size(); !array.isEmpty();index=((index+m)%array.size())){
            System.out.println("remove:"+array.remove(index));
            if(array.size()==1){
                return array.get(0);
            }
        }
        return null;
    }

    public static void main(String[] args){
        System.out.print(new LastNumberInCircle().find(new ArrayList<>(Arrays.asList(new Integer[]{1,2,3,4,5,6,7})),3));
    }
}
